home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / comm / mail / YAM23src.lha / Source / extrasrc / strsfn.c < prev    next >
C/C++ Source or Header  |  2001-02-16  |  1KB  |  61 lines

  1. #include <string.h>
  2. #include "extra.h"
  3.  
  4. /* Build a filename from its components */
  5.  
  6. void strsfn(const char *file, char *drive, char *path, char *node, char *ext)
  7. {
  8.   const char *end = file + strlen(file);
  9.   const char *p = file;
  10.  
  11.   while (*p && *p != ':')
  12.      ++p;
  13.   if (*p++ == ':')
  14.   {
  15.     if (drive)
  16.     {
  17.       memcpy(drive, file, p - file);
  18.       drive += p - file;
  19.     }
  20.     file = p;
  21.   }
  22.   if (drive)
  23.     *drive = '\0';
  24.  
  25.   p = end;
  26.   while (p > file && p[-1] != '.' && p[-1] != '/')
  27.      --p;
  28.   if (ext)
  29.   {
  30.     if (p > file && end - p < FESIZE)
  31.       memcpy(ext, p, end - p + 1);
  32.     else
  33.       *ext = '\0';
  34.   }
  35.   if (p > file)
  36.     end = p - 1;
  37.  
  38.   p = end;
  39.   while (p > file && p[-1] != '/')
  40.     --p;
  41.   if (node)
  42.   {
  43.     if (end > p && end - p < FNSIZE)
  44.     {
  45.       memcpy(node, p, end - p);
  46.       node += end - p;
  47.     }
  48.     *node = '\0';
  49.   }
  50.   end = p > file ? p - 1 : p;
  51.  
  52.   if (path && end > p && end - p < FMSIZE)
  53.   {
  54.     memcpy(path, p, end - p);
  55.     path += end - p;
  56.   }
  57.  
  58.   if (path)
  59.     *path = '\0';
  60. }
  61.